#define _CRT_SECURE_NO_WARNINGS
#pragma once
#include<iostream>
#include<string>
#include<assert.h>

using namespace std;



namespace zhz
{
	class string
	{
	public:

		typedef char* iterator;
		typedef const char* const_iterator;
		//string();
		string(const char* s = "");
		string(const string& s);
		~string();
		//string& operator=(const string& str);
		string& operator=( string str);

		size_t size()const
		{
			return _size;
		}
		size_t capacity()const
		{
			return _capacity;
		}

		const char* c_str()const
		{
			return _str;
		}

		char& operator[](size_t n);
		const char& operator[](size_t n)const;

		void reserve(size_t n);
		void resize(size_t n ,char ch = '\0');

		void push_back(char ch);
		void append(const char* str);
		string& operator+=(char ch);
		string& operator+=(const char* str);

		void Insert(size_t pos, char ch);
		void Insert(size_t pos, const char* str);
		void Erase(size_t pos = 0, size_t len = npos);
		size_t find(char ch, size_t pos = 0);
		size_t find(const char* str, size_t pos = 0);

		string substr(size_t pos = 0, size_t len = npos)const;

		void swap(string& str);
		void clear()
		{
			_str[0] = '\0';
			_size = 0;
		}



		iterator begin()
		{
			return _str;
		}
		const_iterator begin()const
		{
			return _str;
		}
		iterator end()
		{
			return _str + _size;
		}
		const_iterator end()const
		{
			return _str + _size;
		}






	private:
		char* _str = nullptr;
		size_t _size = 0;
		size_t _capacity = 0;

	public:
		static  size_t npos;
	};

	void swap(string& str1, string& str2);

	bool operator== (const string& lhs, const string& rhs);
	bool operator!= (const string& lhs, const string& rhs);
	bool operator<= (const string& lhs, const string& rhs);
	bool operator>= (const string& lhs, const string& rhs);
	bool operator< (const string& lhs, const string& rhs);
	bool operator> (const string& lhs, const string& rhs);


	ostream& operator<<(ostream& os, const string& str);
	istream& operator>>(istream& is,  string& str);
	istream& getline(istream& is, string& str, char delim ='\n');
}